﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Snom
{
    public class SnomKeys
    {
        /// <summary>
        /// "Cancel" key pressed, e.g. a call can be terminated
        /// </summary>
        public const string Cancel = "CANCEL";

        /// <summary>
        /// "Enter" key pressed
        /// </summary>
        public const string Enter = "ENTER";
        /// <summary>
        /// simulates lifting up the handset
        /// </summary>
        public const string OffHook = "OFFHOOK";

        /// <summary>
        /// simulates hanging up the handset
        /// </summary>
        public const string OnHook = "ONHOOK";

        /// <summary>
        /// simulates pressing right navigation key
        /// </summary>
        public const string Right = "RIGHT";

        /// <summary>
        /// simulates pressing left navigation key
        /// </summary>
        public const string Left = "LEFT";

        /// <summary>
        /// simulates pressing "up" navigation key
        /// </summary>
        public const string Up = "UP";

        /// <summary>
        /// simulates pressing "down" navigation key
        /// </summary>
        public const string Down = "DOWN";

        /// <summary>
        /// simulates pressing MENU key (not used in FW 7 anymore)
        /// </summary>
        public const string Menu = "MENU";

        /// <summary>
        /// simulates pressing REDIAL key
        /// </summary>
        public const string Redial = "REDIAL";

        /// <summary>
        /// simulates pressing DND key
        /// </summary>
        public const string Dnd = "DND";

        /// <summary>
        /// simulates pressing context sensitive soft function keys (located directly below the display of the phone) NOTE: snom 190/200 have no key F4 and snom870 no key F1-F4
        /// </summary>
        public const string F1 = "F1";

        /// <summary>
        /// simulates pressing context sensitive soft function keys (located directly below the display of the phone) NOTE: snom 190/200 have no key F4 and snom870 no key F1-F4
        /// </summary>
        public const string F2 = "F2";

        /// <summary>
        /// simulates pressing context sensitive soft function keys (located directly below the display of the phone) NOTE: snom 190/200 have no key F4 and snom870 no key F1-F4
        /// </summary>
        public const string F3 = "F3";

        /// <summary>
        /// simulates pressing context sensitive soft function keys (located directly below the display of the phone) NOTE: snom 190/200 have no key F4 and snom870 no key F1-F4
        /// </summary>
        public const string F4 = "F4";

        /// <summary>
        /// simulates pressing mute key
        /// </summary>
        public const string Mute = "MUTE";

        /// <summary>
        /// simulates pressing SPEAKER key
        /// </summary>
        public const string Speaker = "SPEAKER";

        /// <summary>
        /// simulates pressing TRANSFER key
        /// </summary>
        public const string Transfer = "TRANSFER";

        /// <summary>
        /// simulates pressing HOLD key
        /// </summary>
        public const string Hold = "F_R";

        public const string Key0 = "0";
        public const string Key1 = "1";
        public const string Key2 = "2";
        public const string Key3 = "3";
        public const string Key4 = "4";
        public const string Key5 = "5";
        public const string Key6 = "6";
        public const string Key7 = "7";
        public const string Key8 = "8";
        public const string Key9 = "9";
        public const string KeyStar = "*";
        public const string KeySharp = "%23";

        /// <summary>
        /// simulates pressing free programmable function keys (X=15 for snom870, X=12 for snom320/360/370/820, X=4 for snom300).
        /// </summary>
        public const string ProgramKey1 = "P1";
        public const string ProgramKey2 = "P2";
        public const string ProgramKey3 = "P3";
        public const string ProgramKey4 = "P4";
        public const string ProgramKey5 = "P5";
        public const string ProgramKey6 = "P6";
        public const string ProgramKey7 = "P7";
        public const string ProgramKey8 = "P8";
        public const string ProgramKey9 = "P9";
        public const string ProgramKey10 = "P10";
        public const string ProgramKey11 = "P11";
        public const string ProgramKey12 = "P12";

        /// <summary>
        /// simulates pressing free programmable function keys of expansion module. Note: expansion module Only for snom3xx.
        /// </summary>
        public const string EK0 = "EK0";
        public const string EK1 = "EK1";
        public const string EK2 = "EK2";
        public const string EK3 = "EK3";

        public const string Dtmf0 = "0";
        public const string Dtmf1 = "1";
        public const string Dtmf2 = "2";
        public const string Dtmf3 = "3";
        public const string Dtmf4 = "4";
        public const string Dtmf5 = "5";
        public const string Dtmf6 = "6";
        public const string Dtmf7 = "7";
        public const string Dtmf8 = "8";
        public const string Dtmf9 = "9";
        public const string DtmfStar = "*";
        public const string DtmfSharp = "%23";

        public static string KeyValueFromKeyName(string keyName)
        {
            FieldInfo field = typeof(SnomKeys).GetField(keyName);

            if (field == null)
            {
                return null;
            }
            
            object value = field.GetRawConstantValue();

            return value.ToString();
        }

        public static bool IsDtmf(string keyName)
        {
            switch (keyName)
            {
                case "Dtmf0":
                case "Dtmf1":
                case "Dtmf2":
                case "Dtmf3":
                case "Dtmf4":
                case "Dtmf5":
                case "Dtmf6":
                case "Dtmf7":
                case "Dtmf8":
                case "Dtmf9":
                case "DtmfStar":
                case "DtmfSharp":
                    return true;
            }
            return false;
        }
    }
}
